<template>
	<div class="system-combo-dialog-container">
		<el-dialog :title="state.dialog.title" v-model="state.dialog.isShowDialog" width="450px"
			:close-on-click-modal="false">
			<el-form ref="comboDialogFormRef" :model="state.ruleForm" size="default" label-width="90px">
				<el-row :gutter="35">
					<el-col :xs="24" class="mb20">
						<el-form-item label="标题名称">
							<el-input v-model="state.ruleForm.field" placeholder="请输入标题名称" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" class="mb20">
						<el-form-item label="对应值">
							<el-input v-model="state.ruleForm.value" placeholder="请输入对应值" clearable type="textarea" autosize></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="onCancel" size="default">取 消</el-button>
					<el-button type="primary" @click="onSubmit" size="default">{{ state.dialog.submitTxt }}</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script setup name="systemCompanyDialog">
import { reactive, ref } from 'vue';

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh']);
import { notikApi } from '/@/api/notik/index';
// 定义变量内容
const comboDialogFormRef = ref();
const defaultProps = {
	children: 'children',
	label: 'cname'
}
const state = reactive({
	selcetPlatforms:[],
	platforms: [],
	ruleForm: {
		field: '',
		value: '',
		cname:''
	},
	dialog: {
		isShowDialog: false,
		type: '',
		title: '',
		submitTxt: '',
	},
});

// 打开弹窗
const openDialog = (cname) => {
	state.dialog.title = '新增';
	state.dialog.submitTxt = '新 增';
	state.ruleForm = {
		field: '',
		value: '',
		cname:cname
	}
	state.dialog.isShowDialog = true;
};

// 关闭弹窗
const closeDialog = () => {
	state.dialog.isShowDialog = false;
};
// 取消
const onCancel = () => {
	closeDialog();
};
// 提交
const onSubmit = () => {
	notikApi().add(state.ruleForm).then(async res => {
		closeDialog(); // 关闭弹窗
		emit('refresh');
	})
};


// 暴露变量
defineExpose({
	openDialog,
});
</script>
<style lang="scss" scoped>
:deep(.el-input-number .el-input__inner) {
	text-align: left;
}
.menu-data-tree {
	width: 100%;
	border: 1px solid var(--el-border-color);
	border-radius: var(--el-input-border-radius, var(--el-border-radius-base));
	padding: 5px;
}
</style>
